<?php
class categoryControl extends Control{
	public function index(){
		$this->display();
	}
  
      public function show_chang(){
      	$db=M('category');
      	$data=$db->field("catid,cname,pid,sort")->all();
      	$category = arr::channel($data,"catid","pid",0,2,"&nbsp;&nbsp;&nbsp;&nbsp;");
         $this->assign('category',$category);
      	 $this->display();
      }

  //添加顶级栏目
      public function add(){
    
      	$db=M('category');
     	if($db->add()){
     		$this->success('添加栏目成功');
     	}else{
     		$this->error('添加失败');
     	}
     }
     public function add_show(){
           C("debug",0);
        $path = C("tpl_index_dir") . '/' . C("tplstyle");
        $files = dir::tree($path,'png',1);
        $moban = dir::tree($path,'',0);
        $this->assign("moban",$moban);
      
        $this->assign("tplpath", $path);
        $this->assign("files", $files);
     	$this->display();
     }

     public function add_chang(){
       
        $this->display();
     	
     	
     	
     	$this->display();
     	
     }

    function del(){
        $catid = $_GET['catid'];
        $db = M("category");
        $result  = $db->where("pid='$catid'")->find();
        if($result){
            $this->error("请先删除子目录");
        }else{
            if($db->del($catid)){
                $this->success("删除栏目成功");
            }else{
                $this->error("删除栏目失败，请重试");
            }
        }
    }

    
 function setconfig() {
        $db = M("config");
        $tid = $db->group("tid")->field("tid")->all();
		//select tid from config group by tid ;
        $config = array();
        foreach ($tid as $t) {
          $data = $db->where("tid={$t['tid']}")->all();
            $data = format_config($data);
            $config[$t['tid']] = $data;
        }
        $this->assign("config",$config);
        $this->display();
    }




//模版更换
function selecttemplate() {
       
    }


}



?>